package com.fox.demo2;

//首先创建商品对象、超市对象、购物对象，再调用购物方法进行测试
public class Test {
    public static void main(String[] args) {
        //创建商品对象
        Goods g1 = new Goods("油饼");
        Goods g2 = new Goods("豆浆机");
        Goods g3 = new Goods("黄豆");
        Goods g4 = new Goods("自然堂");
        Goods g5 = new Goods("洁柔");
        //创建超市对象
        Supermarket m = new Supermarket();
        m.setName("大润发");
        m.setStore(new Goods[]{g4, g5});

        Supermarket s = new Supermarket();
        s.setName("家乐福");
        s.setStore(new Goods[]{g1, g2, g3});//给s超市的库存赋值。

        //创建顾客对象
        Consumer c1 = new Consumer();
        c1.setName("张三");

        Consumer c2 = new Consumer();
        c2.setName("李四");

        //购物行为
        Goods go1 = c1.shopping(m, "豆浆机");   //调用购物方法，指定超市和商品名，得到购物结果
        if (go1 != null) {      //对结果进行判断
            System.out.println(c1.getName() + "在" + m.getName() + "买到了" + go1.getName() + "。");
        } else {
            System.out.println(c1.getName() + "在" + m.getName() + ",什么也没有买到。");
        }

        Goods go2 = c2.shopping(s, "豆浆机");
        if (go2 != null) {
            System.out.println(c2.getName() + "在" + s.getName() + "买到了" + go2.getName() + "。");
        } else {
            System.out.println(c2.getName() + "在" + s.getName() + ",什么也没有买到。");
        }
    }

}
